<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>新闻列表</title>
    <link rel="shortcut icon" href="$request.getContextPath()/resources/cws/images/logo.ico" />
    <link rel="stylesheet" type="text/css" href="$request.getContextPath()/resources/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="$request.getContextPath()/resources/layui/css/layui.css">
    <link rel="stylesheet" href="$request.getContextPath()/resources/bootstrap-table/css/bootstrap-table.min.css" >
    <style type="text/css">
        body,.container-fluid{
            padding: 0px;
            margin: 0px;
            width:99.5%;
            height:100%;
        }
        .container-fluid .content{
            padding: 0px;
            margin: 0px;
            width:100%;
            height:100%;
        }
        .container-fluid .content .bootstrap-table{
            padding: 0px;
            margin: 0px;
            width:100%;
            height:100%;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="content">
        <input type="hidden" name="imageURL" value="$!url.zimg()">
        <div id="toolbar">
            #if($shiro.hasPermission('official:news:add'))
                <button type="button" class="btn btn-default btn-sm" onclick="addNews()"><span class="glyphicon glyphicon-plus"></span>添加</button>
            #end
            #if($shiro.hasPermission('official:news:export'))
                #if($model.has('official_news'))
                    <a type="button" class="btn btn-default btn-sm" href="$request.getContextPath()/common/export/excel/official_news/xlsx"><span class="glyphicon glyphicon-export"></span>导出</a>
                #end
            #end
        </div>
        <table id="table"
               data-toggle="table"
               data-toolbar="#toolbar"
               data-show-refresh="true"
               data-search="true"
               data-show-toggle="true"
               data-show-columns="true"
               data-show-export="true"
               data-id-field="id"
               data-show-export="true"
               data-pagination="true"
               data-query-params="queryParams"
               data-query-type="limit"
               data-show-footer="false"
               data-click-to-select="true"
               data-single-select="false"
               data-striped="true"
               data-method="get"
               data-url="$request.getContextPath()/official/news/newsPage"
               data-side-pagination="server"
               data-page-list="[10, 25, 50, 100, ALL]"
               data-show-pagination-switch="true"
               data-id-field="id"
               data-search-on-enter-key="true"
               data-pagination-v-align="bottom"
               data-show-pagination-switch="true">
            <thead>
            <tr>
                <!--<th data-checkbox="true" data-width="40px"></th>-->
                <th data-field="id" data-visible="false">新闻ID</th>
                <th data-field="logo" data-valign="center" data-align="center" data-width="60px" data-formatter="newsLogoImgFormatter" data-classes="headerImg">新闻LOGO</th>
                <th data-field="categoryId" data-valign="center" data-align="center"  data-visible="true">分类ID</th>
                <th data-field="categoryName" data-valign="center" data-align="center" >分类名称</th>
                <th data-field="title" data-valign="center" data-align="center" >新闻标题</th>
                <th data-field="createTime" data-valign="center" data-align="center" >创建时间</th>
                <th data-field="operate" data-formatter="operateFormatter" data-events="operateEvents">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
</body>
<script type="text/javascript" src="$request.getContextPath()/resources/jquery/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="$request.getContextPath()/resources/bootstrap/js/bootstrap.min.js"></script>

<script type="text/javascript" src="$request.getContextPath()/resources/layer/layer.js"></script>
<script type="text/javascript" src="$request.getContextPath()/resources/layui/layui.js"></script>
<script type="text/javascript" src="$request.getContextPath()/resources/layui/lay/modules/element.js"></script>

<script type="text/javascript" src="$request.getContextPath()/resources/bootstrap-table/js/bootstrap-table.min.js"></script>
<script type="text/javascript" src="$request.getContextPath()/resources/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript">
    function newsLogoClick(logo) {
        top.window.layer.open({
            type: 2,
            title :'用户头像',
            maxmin: true,
            content: ['../../common/image/show/'+logo,'yes'],
            area: ['800px', '600px']
        });
    }
    //用户头像展示
    function newsLogoImgFormatter(value, row, index){
        var imageURL=$("input[name='imageURL']").val()+"/"+row.logo;
        return "<img src='"+imageURL+"' name='"+row.logo+"'  width='100%' height='35px' style='margin:-8px;padding:-8px;' class='userHeader' onclick='newsLogoClick(this.name)'/>";
    }
    //添加组织机构
    function addNews(){
        top.window.layer.open({
            type: 2,
            title :'添加新闻',
            maxmin: true,
            content: ['$request.getContextPath()/official/news/newsAdd','yes'],
            area: ['1200px', '800px'],
            end:function(){
                queryNews();
            }
        });
    }
    //表格查询参数
    function queryParams(params) {
        console.log(params);
        return {
            searchContent:params.search,
            beginIndex:params.offset,
            pageSize:params.limit
        };
    }
    //查询组织机构
    function queryNews(){
        var $table = $('#table');
        $table.bootstrapTable("refresh");
    }
    //操作按钮
    var buttons=[];
    var viewNewsPermission="$shiro.hasPermission('official:news:view')";
    if(viewNewsPermission&&viewNewsPermission=="true"){
        buttons.push('<button type="button" class="btn btn-default btn-sm newsDetail"><span class="glyphicon glyphicon-eye-open"></span>查看</button>');
    }
    var editNewsPermission="$shiro.hasPermission('official:news:edit')";
    if(editNewsPermission&&editNewsPermission=="true"){
        buttons.push('<button type="button" class="btn btn-default btn-sm editNews"><span class="glyphicon glyphicon-edit"></span>编辑</button>');
    }
    var deleteNewsPermission="$shiro.hasPermission('official:news:delete')";
    if(deleteNewsPermission&&deleteNewsPermission=="true"){
        buttons.push('<button type="button" class="btn btn-default btn-sm deleteNews"><span class="glyphicon glyphicon-trash"></span>删除</button>');
    }
    function operateFormatter(value, row, index) {
        return buttons.join('');
    }
    //表格点击事件
    var operateEvents = {
        //机构组织详情
        'click .newsDetail': function (e, value, row, index) {
            top.window.layer.open({
                type: 2,
                title :'新闻详情',
                maxmin: true,
                content: ['$request.getContextPath()/official/news/newsView/'+row.id,'yes'],
                area: ['1200px', '800px']
            });
        },
        //编辑新闻分类
        'click .editNews': function (e, value, row, index) {
            top.window.layer.open({
                type: 2,
                title :'编辑新闻',
                maxmin: true,
                content: ['$request.getContextPath()/official/news/newsEdit/'+row.id,'yes'],
                area: ['1200px', '800px'],
                end:function(){
                    queryNews();
                }
            });
        },
        //删除机构组织
        'click .deleteNews': function (e, value, row, index) {
            layer.confirm('你确定要删除新闻【'+row.title+'】吗?', {icon: 3, title:'提示'}, function(index){
                $.post("$request.getContextPath()/official/news/newsDelete/"+row.id,{_method:'delete'},function(data){
                    if(data.code==200){
                        top.layer.msg(data.msg,{
                            icon: 1,
                            skin: 'demo-class',
                            title :'信息',
                            time:2000,
                            area: ['300px', '160px'],
                            offset: 'rb',
                            end :function(){
                                queryNews();
                                layer.close(index);
                            }
                        });
                    }else{
                        layer.alert(data.msg);
                    }
                });
            });
        }
    };
    $(function(){
        msg('新闻列表信息加载完毕');
    });
</script>
</html>
#parse("/portal/account/footer2.html")